package sivan.test;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * LinkedHashMa源码解析
 */
public class LinkedHashMapDemo {

    private static class LRU<K,V> extends LinkedHashMap<K,V> {

        public LRU(int initialCapacity, float loadFactor, boolean accessOrder) {
            super(initialCapacity, loadFactor, accessOrder);
        }

        @Override
        protected boolean removeEldestEntry(Map.Entry<K, V> eldest) {
            if (size() > 5) {
                return true;
            }
            return false;
        }
    }

    public static void main(String[] args) {
        Map<String, String> map = new LRU<>(10, 0.7f, true);
        map.put("name", "xiaowen");
        map.put("age", "1111");
        map.put("school", "jxlgdx");
        map.put("love", "jxlgdx1");
        map.put("price", "jxlgdx2");
        map.put("sex", "boy");
        map.forEach((x, y) -> System.out.println(x + ":" + y));
    }
}
